
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import axios from 'axios'

async function detectPortAndMount() {
	let port = window.location.port || '8000'
	let protocol = window.location.protocol.replace(':', '') || 'http'
	let hostname = window.location.hostname || '127.0.0.1'
	// 生产环境尝试读取 /port.txt
	try {
		const resp = await fetch('/port.txt', {cache: 'no-store'})
		if (resp.ok) {
			port = (await resp.text()).trim()
		}
	} catch (e) {
		// 忽略，开发环境无 port.txt
	}
	// 自动适配 http/https
	let baseURL = `${protocol}://${hostname}`
	if (port && port !== '80' && port !== '443') baseURL += `:${port}`
	axios.defaults.baseURL = baseURL
	createApp(App).use(ElementPlus).mount('#app')
}

detectPortAndMount()
